package org.skyeye.modeling.util;


import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Layout;

public class LayoutUtils {
	public static GridLayout setMargins(int colNums, boolean makeColEqualWidth) {
		GridLayout gridUpLayout = new GridLayout();
		if (colNums > 0)
			gridUpLayout.numColumns = colNums;
		gridUpLayout.makeColumnsEqualWidth = makeColEqualWidth;
		gridUpLayout.marginBottom = 0;
		gridUpLayout.marginTop = 0;
		gridUpLayout.marginHeight = 0;
		gridUpLayout.marginLeft = 0;
		gridUpLayout.marginRight = 0;
		gridUpLayout.marginWidth = 0;
		gridUpLayout.verticalSpacing = 2;
		return gridUpLayout;
	}

	public static void setMarginEquals0(Layout ly) {
		if (ly instanceof GridLayout) {
			GridLayout gridLayout = (GridLayout) ly;
			gridLayout.marginBottom = 0;
			gridLayout.marginTop = 0;
			gridLayout.marginHeight = 0;
			gridLayout.marginLeft = 0;
			gridLayout.marginRight = 0;
			gridLayout.marginWidth = 0;
		}
		if (ly instanceof RowLayout) {
			RowLayout rowLayout = (RowLayout) ly;
			rowLayout.marginBottom = 0;
			rowLayout.marginTop = 0;
			rowLayout.marginHeight = 0;
			rowLayout.marginLeft = 0;
			rowLayout.marginRight = 0;
			rowLayout.marginWidth = 0;
		}
		if (ly instanceof FormLayout) {
			FormLayout formLayout = (FormLayout) ly;
			formLayout.marginBottom = 0;
			formLayout.marginTop = 0;
			formLayout.marginHeight = 0;
			formLayout.marginLeft = 0;
			formLayout.marginRight = 0;
			formLayout.marginWidth = 0;
		}
	}

	public static void setGridDataWidthToLeft(GridData gridData, int length) {
		gridData.horizontalAlignment = GridData.BEGINNING;
		gridData.horizontalIndent = length;
	}
}
